/*
 * 创建日期 2005-10-7
 *
 * 更改所生成文件模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
package com.vanda.report.element;

import java.util.List;

import org.apache.commons.validator.GenericValidator;

import com.vanda.report.ReportException;
import com.vanda.report.ReportInnerData;

/**
 * 标签父类 <br>
 * <p>
 * 
 * @author eagle <br>
 * @version Version 1.00 <br>
 */
public abstract class BeanElement extends Element {
	/** 指定上下文 */
	private String name;
	/** 指定属性名称 */
	private String property;
	
	/** 默认上下文名称 */
	private static final String REPORTDATA = "reportData";
	
	protected Object getNameObject(ReportInnerData reportData) throws ReportException{
		if(GenericValidator.isBlankOrNull(name)){
			return reportData.getContextData();
		}
		
		if(name.equals(REPORTDATA)){
			return reportData;
		}
		Object obj = null;
		try{
			obj = super.getProperty(reportData,name);
		}catch(Exception e){
			throw new ReportException(e);
		}
		
		return obj;
	}
	
	protected Object getListObject(ReportInnerData reportData, String property)
		throws Exception {
		Object contextObj = getNameObject(reportData);
		
		Object objs = null;
		
		if (property.equals(ReportInnerData.REPORT_DATA_SUBARRAY)) {

			if (contextObj instanceof List) {
				objs = (List) contextObj;
			} else {
				objs = (Object[]) contextObj;
			}
		} else {
			objs = super.getProperty(contextObj, property);
		}
		return objs;
	}
	
	/**
	 * @return
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return
	 */
	public String getProperty() {
		return property;
	}

	/**
	 * @param string
	 */
	public void setName(String string) {
		name = string;
	}

	/**
	 * @param string
	 */
	public void setProperty(String string) {
		property = string;
	}

}
